package com.xidian.zhiancloud.service.myyb;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xidian.zhiancloud.dao.SysOrganizationAbandonMapper;
import com.xidian.zhiancloud.dao.SysUserAbandonMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.SysOrganizationAbandon;
import com.xidian.zhiancloud.model.SysUserAbandon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 组织机构
 */
@Service
@Deprecated
public class OrganizationAbandonService extends ServiceImpl<SysOrganizationAbandonMapper, SysOrganizationAbandon> implements IService<SysOrganizationAbandon> {

    @Autowired
    private SysOrganizationAbandonMapper organizationMapper;

    @Autowired
    private SysUserAbandonMapper userMapper;

    //编辑时如果是父部门要判断下面的子模块的机构类型,父部门的机构类型不能小于子模块
    public void patchById(SysOrganizationAbandon record) {
        int orgRes = organizationMapper.updateById(record);
        SysUserAbandon user = new SysUserAbandon();
        user.setOrganizationId(record.getId());
        int useRes = userMapper.updateById(user);
        if (orgRes == 0 && useRes == 0 ) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }

    //删除
    public void deleteById(SysOrganizationAbandon sysOrganizationAbandon){
        int orgRes = organizationMapper.deleteById(sysOrganizationAbandon.getId());
        SysUserAbandon user = new SysUserAbandon();
        user.setOrganizationId(sysOrganizationAbandon.getId());
        int useRes = userMapper.updateById(user);
        if (orgRes == 0 && useRes == 0 ) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }

    //添加时子部门组织机构类型只能小于等于父级部门,要判断是否有安全管理部门,
    public void add(SysOrganizationAbandon sysOrganizationAbandon){
        organizationMapper.insert(sysOrganizationAbandon);
    }

    public List<SysOrganizationAbandon> queryList(Map<String, Object> map) {
        return organizationMapper.queryList(map);
    }

    public int queryTotal(Map<String, Object> map) {
        return organizationMapper.queryTotal(map);
    }

}
